package com.zl.anova
{
	import com.zl.bean.EBean;
	import com.zl.bean.FactorBean;
	import com.zl.bean.HBean;
	import com.zl.bean.HDgBean;
	import com.zl.bean.TBean;
	
	import common.CommonData;
	
	import flash.utils.Dictionary;
	
	import main.mainView;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.controls.CheckBox;
	
	public class HeHfAnova
	{
		
		[Bindable] public var heDataList:ArrayCollection;
		
		[Bindable] public var heDataList1:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList2:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList3:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList4:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList5:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList6:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList7:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList8:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList9:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList10:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList11:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList12:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList13:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList14:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList15:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList16:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList17:ArrayCollection = new ArrayCollection(); 
		[Bindable] public var heDataList18:ArrayCollection = new ArrayCollection(); 
		
		[Bindable] public var hDgList:ArrayCollection = new ArrayCollection();
		[Bindable] public var dataList:ArrayCollection = new ArrayCollection();
		[Bindable] public var data1List:ArrayCollection = new ArrayCollection();
		[Bindable] public var hdList:ArrayCollection = new ArrayCollection(); 
		
		public var level:int = 0;
		
		
		//etc
		private var elementCount:int = 0;
		private var elementArray:Array = [];
		private var elementGroupValueArray:Array = [];
		private var elementGroupList:ArrayCollection = new ArrayCollection(); 
		
		private var resultStr:String = "";
		
		public function calculateAnova(heDataList:ArrayCollection):void{
			this.heDataList = heDataList;
			hdList = new ArrayCollection();
			CommonData.getInstance().step3HDgList.removeAll();
			elementCount = CommonData.getInstance().showNotPassList.length;
			elementArray = new Array();
			
			for(var i:int = 0; i < elementCount; i++){
				var hBean:HBean = new HBean();
				var elementBean:FactorBean = new FactorBean();
				elementBean = (CommonData.getInstance().showNotPassList.getItemAt(i) as HBean).fBean;
				elementArray.push(elementBean);
			}
			
			hDgList.removeAll();
			if(elementCount == 2 || elementCount == 3){
				this.level = 2;
				showStep3HDg(level);
				doAnovaLevel2();
			}
			/*else if(elementCount == 4){
				this.level = 3;
				showStep3HDg(level);
				doAnovaLevel3();
			}*/
			
			else{
				Alert.show("影响因素个数不正确，无法进行水平分析！");
			}
			
			CommonData.getInstance().step3HDgList = hDgList;
		}
		
		private function doAnovaLevel2():void{
			//分组
			var notPassBean1:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(0) as HBean).fBean;
			var notPassBean2:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(1) as HBean).fBean;
			
			if(elementCount == 2){		//两因素二水平
				for each(var item:Object in heDataList){
					/*var notpass1:Number = (notPassBean1.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean1.id]):item[notPassBean1.id];
					var notpass2:Number = (notPassBean2.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean2.id]):item[notPassBean2.id];*/
					
					var notpass1:Number = item[notPassBean1.id];
					var notpass2:Number = item[notPassBean2.id];
					
					//var notpass2:Number = item["attribute"][notPassBean2.id];
					//group2Level2Element(item[notPassBean1.id], item[notPassBean2.id], item[CommonData.getInstance().treeType]);
					group2Level2Element(notpass1, notpass2, item[CommonData.getInstance().treeType]);
				}
				calculateresult2f(notPassBean1, notPassBean2, level);
			}else if(elementCount == 3){		//三因素二水平
				
				var notPassBean3:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(2) as HBean).fBean;
				for each(var item:Object in heDataList){
					/*var not1:Number = (notPassBean1.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean1.id]):item[notPassBean1.id];
					var not2:Number = (notPassBean2.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean2.id]):item[notPassBean2.id];
					var not3:Number = (notPassBean3.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean3.id]):item[notPassBean3.id];*/
					
					var not1:Number = item[notPassBean1.id];
					var not2:Number = item[notPassBean2.id];
					var not3:Number = item[notPassBean3.id];
					
					//group2Level3Element(item[notPassBean1.id], item[notPassBean2.id], item[notPassBean3.id], item[CommonData.getInstance().treeType]);
					group2Level3Element(not1, not2, not3, item[CommonData.getInstance().treeType]);
				}
				calculate3Element2Level(notPassBean1, notPassBean2, notPassBean3, level);
			}
		}
		
		/*private function doAnovaLevel3():void{
			//四因素三水平
			var notPassBean1:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(0) as HBean).fBean;
			var notPassBean2:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(1) as HBean).fBean;
			var notPassBean3:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(2) as HBean).fBean;
			var notPassBean4:FactorBean = (CommonData.getInstance().showNotPassList.getItemAt(3) as HBean).fBean;
			for each(var item:Object in heDataList){
				var not1:Number = (notPassBean1.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean1.id]):item[notPassBean1.id];
				var not2:Number = (notPassBean2.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean2.id]):item[notPassBean2.id];
				var not3:Number = (notPassBean3.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean3.id]):item[notPassBean3.id];
				var not4:Number = (notPassBean4.id.indexOf("@@##") != -1)? (item["attribute"][notPassBean4.id]):item[notPassBean4.id];
				group3Level4Element(not1, not2, not3, not4, item[CommonData.getInstance().treeType]);
			}
			calculate4Element3Level(notPassBean1, notPassBean2, notPassBean3, notPassBean4, level);
		}*/
		
		//显示第三步中的水平范围
		private function showStep3HDg(level:int):void{
			elementGroupList.removeAll();
			for(var i:int=0; i < elementArray.length; i++){
				elementGroupValueArray = new Array();
				//求分组点，min,ha,max
				for(var j:int = 0; j <= level; j++){
					var groupValue:Number = 0;
					if(j == 0){		
						groupValue = elementArray[i].hMin;	//计算最小值  即：groupValueArray[0] = min
					}else if(j == level){	
						groupValue = elementArray[i].hMax;	//计算最大值 即：groupValueArray[1] = max
					}else{
						groupValue = elementGroupValueArray[j-1] + ((elementArray[i].hMax - elementArray[i].hMin)/level);
					}
					elementGroupValueArray.push(groupValue);
				}
				
				for(var m:int = 0; m < level; m++){
					var k:int = m+1;
					var hDg1:HDgBean = new HDgBean(elementArray[i].label + k + "水平", 
						elementGroupValueArray[m].toFixed(4), elementGroupValueArray[m+1].toFixed(4));
					hDgList.addItem(hDg1);
				}
				elementGroupList.addItem(elementGroupValueArray);
			}
		}
		
		private function group2Level2Element(mm:Number,mn:Number,v:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[2];
			if (mm>=hamin && mm<ha1 && mn>=hbmin && mn<hb1){
				heDataList1.addItem(v);
			}else if (mm>=hamin && mm<ha1 && mn>=hb1 && mn<=hbmax){
				heDataList2.addItem(v);
			}else if (mm>=ha1 && mm<=hamax && mn>=hbmin && mn<hb1){
				heDataList3.addItem(v);
			}else if (mm>=ha1 && mm<=hamax && mn>=hb1 && mn<=hbmax){
				heDataList4.addItem(v);
			}
		}
		
		private function group2Level3Element(mm:Number,mn:Number,mk:Number,v:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[2];
			var hcmin:Number = (elementGroupList.getItemAt(2) as Array)[0];
			var hc1:Number = (elementGroupList.getItemAt(2) as Array)[1];
			var hcmax:Number = (elementGroupList.getItemAt(2) as Array)[2];
			
			if (mm>=hamin&&mm<ha1&&mn>=hbmin&&mn<hb1&&mk>=hcmin&&mk<hc1){//m2m3m5为三因素，实验水平分别为111
				heDataList1.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hbmin&&mn<hb1&&mk>=hc1&&mk<=hcmax){    //112
				heDataList2.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hb1&&mn<=hbmax&&mk>=hcmin&&mk<hc1){    //121
				heDataList3.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hb1&&mn<=hbmax&&mk>=hc1&&mk<=hcmax){    //122
				heDataList4.addItem(v);
			}else if (mm>=ha1&&mm<=hamax&&mn>=hbmin&&mn<hb1&&mk>=hcmin&&mk<hc1){   //211
				heDataList5.addItem(v);
			}else if (mm>=ha1&&mm<=hamax&&mn>=hbmin&&mn<hb1&&mk>=hc1&&mk<=hcmax){    //212
				heDataList6.addItem(v);
			}else if (mm>=ha1&&mm<=hamax&&mn>=hb1&&mn<=hbmax&&mk>=hcmin&&mk<hc1){   //221 
				heDataList7.addItem(v);
			}else if (mm>=ha1&&mm<=hamax&&mn>=hb1&&mn<=hbmax&&mk>=hc1&&mk<=hcmax){//222
				heDataList8.addItem(v);
			}
		}
		
		/*private function group3Level4Element(mm:Number,mn:Number,mk:Number,ml:Number,v:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var ha2:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[3];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hb2:Number = (elementGroupList.getItemAt(1) as Array)[2];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[3];
			var hcmin:Number = (elementGroupList.getItemAt(2) as Array)[0];
			var hc1:Number = (elementGroupList.getItemAt(2) as Array)[1];
			var hc2:Number = (elementGroupList.getItemAt(2) as Array)[2];
			var hcmax:Number = (elementGroupList.getItemAt(2) as Array)[3];
			var hdmin:Number = (elementGroupList.getItemAt(3) as Array)[0];
			var hd1:Number = (elementGroupList.getItemAt(3) as Array)[1];
			var hd2:Number = (elementGroupList.getItemAt(3) as Array)[2];
			var hdmax:Number = (elementGroupList.getItemAt(3) as Array)[3];
			if (mm>=hamin&&mm<ha1&&mn>=hbmin&&mn<hb1&&mk>=hcmin&&mk<hc1&&ml>=hdmin&&ml<hd1){//4因素，实验水平分别为1111
				heDataList1.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hb1&&mn<hb2&&mk>=hc1&&mk<hc2&&ml>=hd1&&ml<hd2){    //1222
				heDataList2.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hb2&&mn<=hbmax&&mk>=hc2&&mk<=hcmax&&ml>=hd2&&ml<=hdmax){    //1333
				heDataList3.addItem(v);
			}else if (mm>=ha1&&mm<ha2&&mn>=hbmin&&mn<hb1&&mk>=hc1&&mk<hc2&&ml>=hd2&&ml<=hdmax){    //2123
				heDataList4.addItem(v);
			}else if (mm>=ha1&&mm<ha2&&mn>=hb1&&mn<hb2&&mk>=hc2&&mk<=hcmax&&ml>=hdmin&&ml<hd1){    //2231
				heDataList5.addItem(v);
			}else if (mm>=ha1&&mm<ha2&&mn>=hb2&&mn<=hbmax&&mk>=hcmin&&mk<hc1&&ml>=hd1&&ml<hd2){    //2312
				heDataList6.addItem(v);
			}else if (mm>=ha2&&mm<=hamax&&mn>=hbmin&&mn<hb1&&mk>=hc2&&mk<=hcmax&&ml>=hd1&&ml<hd2){    //3132
				heDataList7.addItem(v);
			}else if (mm>=ha2&&mm<=hamax&&mn>=hb1&&mn<hb2&&mk>=hcmin&&mk<hc1&&ml>=hd2&&ml<=hdmax){    //3213
				heDataList8.addItem(v);
			}else if (mm>=ha2&&mm<=hamax&&mn>=hb2&&mn<=hbmax&&mk>=hc1&&mk<hc2&&ml>=hdmin&&ml<hd1){    //3321
				heDataList9.addItem(v);
			}else if (mm>=ha1&&mm<ha2&&mn>=hbmin&&mn<hb1&&mk>=hcmin&&mk<hc1&&ml>=hd1&&ml<hd2){   //2112
				heDataList10.addItem(v);
			}else if (mm>=ha1&&mm<ha2&&mn>=hb1&&mn<hb2&&mk>=hc1&&mk<hc2&&ml>=hd2&&ml<=hdmax){    //2223
				heDataList11.addItem(v);
			}else if (mm>=ha1&&mm<ha2&&mn>=hb2&&mn<=hbmax&&mk>=hc2&&mk<=hcmax&&ml>=hdmin&&ml<hd1){    //2331
				heDataList12.addItem(v);
			}else if (mm>=ha2&&mm<=hamax&&mn>=hbmin&&mn<hb1&&mk>=hc1&&mk<hc2&&ml>=hdmin&&ml<hd1){    //3121
				heDataList13.addItem(v);
			}else if (mm>=ha2&&mm<=hamax&&mn>=hb1&&mn<hb2&&mk>=hc2&&mk<=hcmax&&ml>=hd1&&ml<hd2){    //3232
				heDataList14.addItem(v);
			}else if (mm>=ha2&&mm<=hamax&&mn>=hb2&&mn<=hbmax&&mk>=hcmin&&mk<hc1&&ml>=hd2&&ml<=hdmax){    //3313
				heDataList15.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hbmin&&mn<hb1&&mk>=hc2&&mk<=hcmax&&ml>=hd2&&ml<=hdmax){    //1133
				heDataList16.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hb1&&mn<hb2&&mk>=hcmin&&mk<hc1&&ml>=hdmin&&ml<hd1){    //1211
				heDataList17.addItem(v);
			}else if (mm>=hamin&&mm<ha1&&mn>=hb2&&mn<=hbmax&&mk>=hc1&&mk<hc2&&ml>=hd1&&ml<hd2){   //1322
				heDataList18.addItem(v);
			}
		}*/
		
		private function analysis2f(Y1:Number,Y2:Number,Y3:Number,Y4:Number,s1:String, s2:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[2];
			var alertStr1:String = "数据不足，无法进行分析，请进行相应水平的实验并重新分析！";
			var alertStr2:String = "对应水平的数据范围为:";
			var alertStr3:String = ""; 
			var i:uint = 0;
			if(Y1==0){
				i++;
				alertStr3 += i+'、'+s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
			}
			if(Y2==0){
				i++;
				alertStr3 += i+'、'+s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hb1.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
			}
			if(Y3==0){
				i++;
				alertStr3 += i+'、'+s1+':'+ha1.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
			}
			if(Y4==0){
				i++;
				alertStr3 += i+'、'+s1+':'+ha1.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hb1.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
			}
			Alert.show(alertStr1+'\n'+alertStr2+'\n'+alertStr3);
			CommonData.getInstance().step3Result = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>";
			CommonData.getInstance().step3Pro =  "<font color='#0000ff' size='12'>最优组合：</font>";
		}
		
		private function showresult2f(a:Number, b:Number, d:Number, ave1:Number, ave2:Number,ave3:Number,
				ave4:Number, s1:String,  s2:String, s4:String, s5:String, s6:String,s7:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[2];
			CommonData.getInstance().step3Result = "";
			CommonData.getInstance().step3Pro = "";
			resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>";
			var proStr:String = "<font color='#0000ff' size='12'>最优组合：</font>";
			if (a>=d){
				if (b>=d){
					if (a>=b){
						resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+s1+" > "+s2;
					}
					else if (a<b){
						resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+s2+" > "+s1;
					}
				}else if (b<d){
					resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+s1+" > "+s2;
				}
			}else if (a<d){
				if (b>=d){
					resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+s2+" > "+s1;
				}else if (b<d){
					if (a>=b){			
						resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+s1+" > "+s2;
					}else if (a<b){
						resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+s2+" > "+s1;
					}
				}
			}
			CommonData.getInstance().step3Result = resultStr;
			if (ave1>ave2&&ave3>ave4){
				proStr = "<font color='#0000ff' size='12'>最优组合：</font>\n\n" + s4 + "、"+s6  +";\n\n" + 
					"对应水平的数据范围为：\n"+s1+":"+hamin.toFixed(4)+"-"+ha1.toFixed(4)+"\n"+s2+":"+hbmin.toFixed(4)+"-"+hb1.toFixed(4);
			}else if (ave1>ave2&&ave3<=ave4){
				proStr = "<font color='#0000ff' size='12'>最优组合：</font>\n\n" + s4 + "、"+s7  +";\n\n" + 
					"对应水平的数据范围为：\n"+s1+":"+hamin.toFixed(4)+"-"+ha1.toFixed(4)+"\n"+s2+":"+hb1.toFixed(4)+"-"+hbmax.toFixed(4);
			}else if (ave1<=ave2&&ave3>ave4){
				proStr = "<font color='#0000ff' size='12'>最优组合：</font>\n\n" + s5 + "、"+s6  +";\n\n" + 
					"对应水平的数据范围为：\n"+s1+":"+ha1.toFixed(4)+"-"+hamax.toFixed(4)+"\n"+s2+":"+hbmin.toFixed(4)+"-"+hb1.toFixed(4);
			}else if (ave1<=ave2&&ave3<=ave4){
				proStr = "<font color='#0000ff' size='12'>最优组合：</font>\n\n" + s5 + "、"+s7  +";\n\n" + 
					"对应水平的数据范围为：\n"+s1+":"+ha1.toFixed(4)+"-"+hamax.toFixed(4)+"\n"+s2+":"+hb1.toFixed(4)+"-"+hbmax.toFixed(4);
			}
			CommonData.getInstance().step3Pro = proStr;
		}
		
		private function calculateresult2f(notPassBean1:FactorBean, notPassBean2:FactorBean, level:int):void{
			CommonData.getInstance().step3SDgList.removeAll();
			var Y1:Number = calculatey(heDataList1);
			var Y2:Number = calculatey(heDataList2);
			var Y3:Number = calculatey(heDataList3);
			var Y4:Number = calculatey(heDataList4);
			
			if(Y1==0 || Y2 ==0 || Y3 == 0 || Y4 ==0){
				analysis2f(Y1,Y2,Y3,Y4,notPassBean1.label, notPassBean2.label);
			}else{
				var k:int = 2;
				var avey:Number=(Y1+Y2+Y3+Y4)/4;
				var aveAT1:Number = (Y1 + Y2) /2;
				var aveAT2:Number = (Y3 + Y4) /2;
				var aveBT1:Number = (Y1 + Y3) /2;
				var aveBT2:Number = (Y2 + Y4) /2;
				
				var SA:Number = ((aveAT1-avey)*(aveAT1-avey)+(aveAT2-avey)*(aveAT2-avey))*k;
				var SB:Number = ((aveBT1-avey)*(aveBT1-avey)+(aveBT2-avey)*(aveBT2-avey))*k;
				
				var ST:Number = (Y1-avey)*(Y1-avey)+(Y2-avey)*(Y2-avey)
					+(Y3-avey)*(Y3-avey)+(Y4-avey)*(Y4-avey);
				
				var Se:Number = ST-SA-SB;
				
				var fA:Number = (level-1);
				var fB:Number = (level-1);
				var fT:Number = (level*k-1);//水平数*实验重复次数
				var fe:Number = fT-fA-fB;
				
				var MSA:Number = SA/fA;
				var MSB:Number = SB/fB;
				
				var MSe:Number = Se/fe;
				
				var FA:Number = MSA/MSe;
				var FB:Number = MSB/MSe;
				
				var F:Number = 39.86;//需比较的F值*/
				
				var hBean:HBean;
				var eBean:EBean = new EBean();
				var tBean:TBean = new TBean();
				
				hBean = new HBean();
				hBean.title = notPassBean1.label;
				hBean.sNum = SA.toFixed(4);
				hBean.fNum = fA.toString();
				hBean.msNum = MSA.toFixed(4);
				hBean.FANum = FA.toFixed(4);
				data1List.addItem(hBean);
				
				hBean = new HBean();
				hBean.title = notPassBean2.label;
				hBean.sNum = SB.toFixed(4);
				hBean.fNum = fB.toString();
				hBean.msNum = MSB.toFixed(4);
				hBean.FANum = FB.toFixed(4);
				data1List.addItem(hBean);
				
				eBean.title = "e";
				eBean.sNum = Se.toFixed(4);
				eBean.fNum = fe.toString();
				eBean.msNum = MSe.toFixed(4);
				eBean.FANum = "-";
				
				tBean.title = "T";
				tBean.sNum = ST.toFixed(4);
				tBean.fNum = fT.toString();
				tBean.msNum = "-";
				tBean.FANum = F.toFixed(4);
				data1List.addItem(eBean);
				data1List.addItem(tBean);
				CommonData.getInstance().step3SDgList = data1List;
				
				
				showresult2f(FA,FB,F,aveAT1,aveAT2,aveBT1,aveBT2,notPassBean1.label, notPassBean2.label,
					notPassBean1.label + "1水平", notPassBean1.label + "2水平", notPassBean2.label + "1水平",notPassBean2.label + "2水平");
			}
			/*if(Y1==0 || Y2 ==0 || Y3 == 0 || Y4 ==0){
				analysis2f(Y1,Y2,Y3,Y4,notPassBean1.label, notPassBean2.label);
			}else{
				showresult2f(FA,FB,F,aveAT1,aveAT2,aveBT1,aveBT2,notPassBean1.label, notPassBean2.label,
					notPassBean1.label + "1水平", notPassBean1.label + "2水平", notPassBean2.label + "1水平",notPassBean2.label + "2水平");
			}*/
		}
		
		private function calculate3Element2Level(notPassBean1:FactorBean, notPassBean2:FactorBean,notPassBean3:FactorBean, level:int):void{
			CommonData.getInstance().step3SDgList.removeAll();
			var Y1:Number = calculatey(heDataList1);
			var Y2:Number = calculatey(heDataList2);
			var Y3:Number = calculatey(heDataList3);
			var Y4:Number = calculatey(heDataList4);
			var Y5:Number = calculatey(heDataList5);
			var Y6:Number = calculatey(heDataList6);
			var Y7:Number = calculatey(heDataList7);
			var Y8:Number = calculatey(heDataList8);
			
			if(Y1==0 || Y2 ==0 || Y3 == 0 || Y4 ==0 || Y5==0 || Y6 ==0 || Y7 == 0 || Y8 ==0){
				analysis3f(Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8,notPassBean1.label, notPassBean2.label, notPassBean3.label);
			}else{
				var k:int = 4;
				var avey:Number=(Y1+Y2+Y3+Y4+Y5+Y6+Y7+Y8)/8;
				var aveAT1:Number = (Y1 + Y2 + Y3 + Y4) /4;
				var aveAT2:Number = (Y5 + Y6 + Y7 + Y8) /4;
				var aveBT1:Number = (Y1 + Y2 + Y5 + Y6) /4;
				var aveBT2:Number = (Y3 + Y4 + Y7 + Y8) /4;
				var aveCT1:Number = (Y1 + Y3 + Y5 + Y7) /4;
				var aveCT2:Number = (Y2 + Y4 + Y6 + Y8) /4;
				
				var aveAArry:Array =[];
				aveAArry.push(aveAT1);	
				aveAArry.push(aveAT2);	
				var indexA:int = calculateIndex(aveAArry);
				
				var aveBArry:Array =[];
				aveBArry.push(aveBT1);	
				aveBArry.push(aveBT2);	
				var indexB:int = calculateIndex(aveBArry);
				
				var aveCArry:Array =[];
				aveCArry.push(aveCT1);	
				aveCArry.push(aveCT2);	
				var indexC:int = calculateIndex(aveCArry);
				
				var SA:Number = ((aveAT1-avey)*(aveAT1-avey)+(aveAT2-avey)*(aveAT2-avey))*k;
				var SB:Number = ((aveBT1-avey)*(aveBT1-avey)+(aveBT2-avey)*(aveBT2-avey))*k;
				var SC:Number = ((aveCT1-avey)*(aveCT1-avey)+(aveCT2-avey)*(aveCT2-avey))*k;
				
				var ST:Number = (Y1-avey)*(Y1-avey)+(Y2-avey)*(Y2-avey)
					+(Y3-avey)*(Y3-avey)+(Y4-avey)*(Y4-avey)
					+(Y5-avey)*(Y5-avey)+(Y6-avey)*(Y6-avey)
					+(Y7-avey)*(Y7-avey)+(Y8-avey)*(Y8-avey);
				
				var Se:Number = ST-SA-SB-SC;
				
				var fA:Number = (level-1);
				var fB:Number = (level-1);
				var fC:Number = (level-1);
				var fT:Number = (level*k-1);//水平数*实验重复次数
				var fe:Number = fT-fA-fB-fC;
				
				var MSA:Number = SA/fA;
				var MSB:Number = SB/fB;
				var MSC:Number = SC/fC;
				
				var MSe:Number = Se/fe;
				
				var FA:Number = MSA/MSe;
				var FB:Number = MSB/MSe;
				var FC:Number = MSC/MSe;
				
				var F:Number = 4.54;//需比较的F值*/
				
				var hBean:HBean;
				var eBean:EBean = new EBean();
				var tBean:TBean = new TBean();
				
				hBean = new HBean();
				hBean.title = notPassBean1.label;
				hBean.sNum = SA.toFixed(4);
				hBean.fNum = fA.toString();
				hBean.msNum = MSA.toFixed(4);
				hBean.FANum = FA.toFixed(4);
				data1List.addItem(hBean);
				
				hBean = new HBean();
				hBean.title = notPassBean2.label;
				hBean.sNum = SB.toFixed(4);
				hBean.fNum = fB.toString();
				hBean.msNum = MSB.toFixed(4);
				hBean.FANum = FB.toFixed(4);
				data1List.addItem(hBean);
				
				hBean = new HBean();
				hBean.title = notPassBean3.label;
				hBean.sNum = SC.toFixed(4);
				hBean.fNum = fC.toString();
				hBean.msNum = MSC.toFixed(4);
				hBean.FANum = FC.toFixed(4);
				data1List.addItem(hBean);
				
				eBean.title = "e";
				eBean.sNum = Se.toFixed(4);
				eBean.fNum = fe.toString();
				eBean.msNum = MSe.toFixed(4);
				eBean.FANum = "-";
				
				tBean.title = "T";
				tBean.sNum = ST.toFixed(4);
				tBean.fNum = fT.toString();
				tBean.msNum = "-";
				tBean.FANum = F.toFixed(4);
				data1List.addItem(eBean);
				data1List.addItem(tBean);
				CommonData.getInstance().step3SDgList = data1List;
				
				showresult3E2L(FA,FB,FC,F,indexA,indexB,indexC);
			}
		}
		
		private function showresult3E2L(a:Number, b:Number, c:Number,f:Number, indexA:Number, indexB:Number,indexC:Number):void{
			CommonData.getInstance().step3Result = "";
			CommonData.getInstance().step3Pro = "";
			var resultStr:String = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>";
			
			var eArray:Array = [];
			var tempArray:Array = [];
			var resultArray:Array = [];
			
			eArray.push({productName:elementArray[0].label,version:a});
			eArray.push({productName:elementArray[1].label,version:b});
			eArray.push({productName:elementArray[2].label,version:c});
			eArray.sortOn("version",Array.NUMERIC);
			for(var i:int=0; i<eArray.length; i++){
				resultArray.push(eArray[i].productName);
			}
			resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+resultArray[2]+" > "+resultArray[1]+" > "+resultArray[0];
			CommonData.getInstance().step3Result = resultStr;
			
			var proStr:String = "<font color='#0000ff' size='12'>最优组合：</font>";
			var ma:int = indexA + 1;
			var labelA:String = elementArray[0].label + ma + "水平";
			var mb:int = indexB + 1;
			var labelB:String = elementArray[1].label + mb + "水平";
			var mc:int = indexC + 1;
			var labelC:String = elementArray[2].label + mc + "水平";
			proStr = "<font color='#0000ff' size='12'>最优组合：</font>\n\n" + labelA + "、"+ labelB  + "、" + labelC+ ";\n\n"
			+ "对应水平的数据范围为：\n"+elementArray[0].label+":"+(elementGroupList.getItemAt(0) as Array)[indexA].toFixed(4)+"-"+(elementGroupList.getItemAt(0) as Array)[indexA+1].toFixed(4)
				+"\n"+elementArray[1].label+":"+(elementGroupList.getItemAt(1) as Array)[indexB].toFixed(4)+"-"+(elementGroupList.getItemAt(1) as Array)[indexB+1].toFixed(4)
				+"\n"+elementArray[2].label+":"+(elementGroupList.getItemAt(2) as Array)[indexC].toFixed(4)+"-"+(elementGroupList.getItemAt(2) as Array)[indexC+1].toFixed(4);
			CommonData.getInstance().step3Pro = proStr;
		}
		
		private function analysis3f(Y1:Number,Y2:Number,Y3:Number,Y4:Number,Y5:Number,Y6:Number,
									Y7:Number,Y8:Number,s1:String, s2:String, s3:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[2];
			var hcmin:Number = (elementGroupList.getItemAt(2) as Array)[0];
			var hc1:Number = (elementGroupList.getItemAt(2) as Array)[1];
			var hcmax:Number = (elementGroupList.getItemAt(2) as Array)[2];
			
			var alertStr1:String = "数据不足，无法进行分析，请进行相应水平的实验并重新分析！";
			var alertStr2:String = "对应水平的数据范围为:";
			var alertStr3:String = ""; 
			var i:uint = 0;
			if(Y1==0){
				i++;
				alertStr3 += i+'、'+s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hcmin.toFixed(4)+'-'+hc1.toFixed(4)+'\n';
			}
			if(Y2==0){
				i++;
				alertStr3 += i+'、'+s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hc1.toFixed(4)+'-'+hcmax.toFixed(4)+'\n';
			}
			if(Y3==0){
				i++;
				alertStr3 += i+'、'+s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hb1.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hcmin.toFixed(4)+'-'+hc1.toFixed(4)+'\n';
			}
			if(Y4==0){
				i++;
				alertStr3 += i+'、'+s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hb1.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hc1.toFixed(4)+'-'+hcmax.toFixed(4)+'\n';
			}
			if(Y5 == 0){
				i++;
				alertStr3 += i+'、'+s1+':'+ha1.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hcmin.toFixed(4)+'-'+hc1.toFixed(4)+'\n';
			}
			if(Y6 == 0){
				i++;
				alertStr3 += i+'、'+s1+':'+ha1.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hc1.toFixed(4)+'-'+hcmax.toFixed(4)+'\n';
			}
			if(Y7 == 0){
				i++;
				alertStr3 += i+'、'+s1+':'+ha1.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hb1.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hcmin.toFixed(4)+'-'+hc1.toFixed(4)+'\n';
				
			}
			if(Y8 == 0){
				alertStr3 += i+'、'+s1+':'+ha1.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
				alertStr3 += '   '+s2+':'+hb1.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
				alertStr3 += '   '+s3+':'+hc1.toFixed(4)+'-'+hcmax.toFixed(4)+'\n';
			}
			
			Alert.show(alertStr1+'\n'+alertStr2+'\n'+alertStr3);
			CommonData.getInstance().step3Result = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>";
			CommonData.getInstance().step3Pro =  "<font color='#0000ff' size='12'>最优组合：</font>";
		}
		
		private function analysis4f(Y1:Number,Y2:Number,Y3:Number,Y4:Number,Y5:Number,Y6:Number,Y7:Number,Y8:Number,Y9:Number, Y10:Number,
									Y11:Number,Y12:Number,Y13:Number,Y14:Number,Y15:Number,Y16:Number,Y17:Number,Y18:Number,
									s1:String, s2:String, s3:String, s4:String):void{
			var hamin:Number = (elementGroupList.getItemAt(0) as Array)[0];
			var ha1:Number = (elementGroupList.getItemAt(0) as Array)[1];
			var ha2:Number = (elementGroupList.getItemAt(0) as Array)[2];
			var hamax:Number = (elementGroupList.getItemAt(0) as Array)[3];
			var hbmin:Number = (elementGroupList.getItemAt(1) as Array)[0];
			var hb1:Number = (elementGroupList.getItemAt(1) as Array)[1];
			var hb2:Number = (elementGroupList.getItemAt(1) as Array)[2];
			var hbmax:Number = (elementGroupList.getItemAt(1) as Array)[3];
			var hcmin:Number = (elementGroupList.getItemAt(2) as Array)[0];
			var hc1:Number = (elementGroupList.getItemAt(2) as Array)[1];
			var hc2:Number = (elementGroupList.getItemAt(2) as Array)[2];
			var hcmax:Number = (elementGroupList.getItemAt(2) as Array)[3];
			var hdmin:Number = (elementGroupList.getItemAt(3) as Array)[0];
			var hd1:Number = (elementGroupList.getItemAt(3) as Array)[1];
			var hd2:Number = (elementGroupList.getItemAt(3) as Array)[2];
			var hdmax:Number = (elementGroupList.getItemAt(3) as Array)[3];
			
			var a1:String = s1+':'+hamin.toFixed(4)+'-'+ha1.toFixed(4)+'\n';
			var a2:String = s1+':'+ha1.toFixed(4)+'-'+ha2.toFixed(4)+'\n';
			var a3:String = s1+':'+ha2.toFixed(4)+'-'+hamax.toFixed(4)+'\n';
			
			var b1:String = s2+':'+hbmin.toFixed(4)+'-'+hb1.toFixed(4)+'\n';
			var b2:String = s2+':'+hb1.toFixed(4)+'-'+hb2.toFixed(4)+'\n';
			var b3:String = s2+':'+hb2.toFixed(4)+'-'+hbmax.toFixed(4)+'\n';
			
			var c1:String = s3+':'+hcmin.toFixed(4)+'-'+hc1.toFixed(4)+'\n';
			var c2:String = s3+':'+hc1.toFixed(4)+'-'+hc2.toFixed(4)+'\n';
			var c3:String = s3+':'+hc2.toFixed(4)+'-'+hcmax.toFixed(4)+'\n';
			
			var d1:String = s4+':'+hdmin.toFixed(4)+'-'+hd1.toFixed(4)+'\n';
			var d2:String = s4+':'+hd1.toFixed(4)+'-'+hd2.toFixed(4)+'\n';
			var d3:String = s4+':'+hd2.toFixed(4)+'-'+hdmax.toFixed(4)+'\n';
			
			var alertStr1:String = "数据不足，无法进行分析，请进行相应水平的实验并重新分析！";
			var alertStr2:String = "对应水平的数据范围为:";
			var alertStr3:String = ""; 
			var i:uint = 0;
			if(Y1 == 0){		//1111
				i++;
				alertStr3 += i + '、'+ a1 +  '   ' + b1 +  '   ' + c1 +  '   ' + d1;
			}
			if(Y2 == 0){		//1222
				i++;
				alertStr3 += i + '、'+ a1 +  '   ' + b2 +  '   ' + c2 +  '   ' + d2;
			}
			if(Y3 == 0){		//1333
				i++;
				alertStr3 += i + '、'+ a1 +  '   ' + b3 +  '   ' + c3 +  '   ' + d3;
			}
			if(Y4 == 0){		//2123
				i++;
				alertStr3 += i + '、'+ a2 +  '   ' + b1 +  '   ' + c3 +  '   ' + d3;
			}
			if(Y5 == 0){		//2231
				i++;
				alertStr3 += i + '、'+ a2 +  '   ' + b2 +  '   ' + c3 +  '   ' + d1;
			}
			if(Y6 == 0){		//2312
				i++;
				alertStr3 += i + '、'+ a2 +  '   ' + b3 +  '   ' + c1 +  '   ' + d2;
			}
			if(Y7 == 0){		//3132
				i++;
				alertStr3 += i + '、'+ a3 +  '   ' + b1 +  '   ' + c3 +  '   ' + d2;
			}
			if(Y8 == 0){		//3213
				i++;
				alertStr3 += i + '、'+ a3 +  '   ' + b2 +  '   ' + c1 +  '   ' + d3
			}
			if(Y9 == 0){		//3321
				i++;
				alertStr3 += i + '、'+ a3 +  '   ' + b3 +  '   ' + c2 +  '   ' + d1;
			}
			if(Y10 == 0){		//2112
				i++;
				alertStr3 += i + '、'+ a2 +  '   ' + b1 +  '   ' + c1 +  '   ' + d2;
			}
			if(Y11 == 0){		//2223
				i++;
				alertStr3 += i + '、'+ a2 +  '   ' + b2 +  '   ' + c2 +  '   ' + d3;
			}
			if(Y12 == 0){		//2331
				i++;
				alertStr3 += i + '、'+ a2 +  '   ' + b3 +  '   ' + c3 +  '   ' + d1;
			}
			if(Y13 == 0){		//3121
				i++;
				alertStr3 = i + '、'+ a3 +  '   ' + b1 +  '   ' + c2 +  '   ' + d1;
			}
			if(Y14 == 0){		//3232
				i++;
				alertStr3 += i + '、'+ a3 +  '   ' + b2 +  '   ' + c3 +  '   ' + d2;
			}
			if(Y15 == 0){		//3313
				i++;
				alertStr3 += i + '、'+ a3 +  '   ' + b3 +  '   ' + c1 +  '   ' + d3;
			}
			if(Y16 == 0){		//1133
				i++;
				alertStr3 += i + '、'+ a1 +  '   ' + b1 +  '   ' + c3 +  '   ' + d3;
			}
			if(Y17 == 0){		//1211
				i++;
				alertStr3 += i + '、'+ a1 +  '   ' + b2 +  '   ' + c1 +  '   ' + d1;
			}
			if(Y18 == 0){		//1322
				i++;
				alertStr3 += i + '、'+ a1 +  '   ' + b3 +  '   ' + c2 +  '   ' + d2;
			}
			Alert.show(alertStr1+'\n'+alertStr2+'\n'+alertStr3);
			CommonData.getInstance().step3Result = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>";
			CommonData.getInstance().step3Pro =  "<font color='#0000ff' size='12'>最优组合：</font>";
		}
		
		private function showresult4E3L(a:Number, b:Number, c:Number,d:Number, f:Number, indexA:Number, indexB:Number, indexC:Number, indexD:Number):void{
			CommonData.getInstance().step3Result = "";
			CommonData.getInstance().step3Pro = "";
			var resultStr:String = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>";
			
			var eArray:Array = [];
			var tempArray:Array = [];
			var resultArray:Array = [];
			
			eArray.push({productName:elementArray[0].label,version:a});
			eArray.push({productName:elementArray[1].label,version:b});
			eArray.push({productName:elementArray[2].label,version:c});
			eArray.push({productName:elementArray[3].label,version:d});
			eArray.sortOn("version",Array.NUMERIC);
			for(var i:int=0; i<eArray.length; i++){
				resultArray.push(eArray[i].productName);
			}
			resultStr = "<font color='#0000ff' size='12'>各因数影响结果比较：</font>\n\n影响程度为："+resultArray[3]+" > "+resultArray[2]+" > "+resultArray[1]+" > "+resultArray[0];
			CommonData.getInstance().step3Result = resultStr;
			
			var proStr:String = "<font color='#0000ff' size='12'>最优组合：</font>";
			var ma:int = indexA + 1;
			var labelA:String = elementArray[0].label + ma + "水平";
			var mb:int = indexB + 1;
			var labelB:String = elementArray[1].label + mb + "水平";
			var mc:int = indexC + 1;
			var labelC:String = elementArray[2].label + mc + "水平";
			var md:int = indexD + 1;
			var labelD:String = elementArray[3].label + md + "水平";
			proStr = "<font color='#0000ff' size='12'>最优组合：</font>\n\n" + labelA + "、"+ labelB  + "、" + labelC+ "、"+ labelD + ";\n\n"
				+ "对应水平的数据范围为：\n"+elementArray[0].label+":"+(elementGroupList.getItemAt(0) as Array)[indexA].toFixed(4)+"-"+(elementGroupList.getItemAt(0) as Array)[indexA+1].toFixed(4)
				+"\n"+elementArray[1].label+":"+(elementGroupList.getItemAt(1) as Array)[indexB].toFixed(4)+"-"+(elementGroupList.getItemAt(1) as Array)[indexB+1].toFixed(4)
				+"\n"+elementArray[2].label+":"+(elementGroupList.getItemAt(2) as Array)[indexC].toFixed(4)+"-"+(elementGroupList.getItemAt(2) as Array)[indexC+1].toFixed(4)
				+"\n"+elementArray[3].label+":"+(elementGroupList.getItemAt(3) as Array)[indexD].toFixed(4)+"-"+(elementGroupList.getItemAt(3) as Array)[indexD+1].toFixed(4);
			CommonData.getInstance().step3Pro = proStr;
		}
		
		/*private function calculate4Element3Level(notPassBean1:FactorBean, 
				notPassBean2:FactorBean, notPassBean3:FactorBean, notPassBean4:FactorBean, level:int):void{
			var Y1:Number = calculatey(heDataList1);
			var Y2:Number = calculatey(heDataList2);
			var Y3:Number = calculatey(heDataList3);
			var Y4:Number = calculatey(heDataList4);
			var Y5:Number = calculatey(heDataList5);
			var Y6:Number = calculatey(heDataList6);
			var Y7:Number = calculatey(heDataList7);
			var Y8:Number = calculatey(heDataList8);
			var Y9:Number = calculatey(heDataList9);
			var Y10:Number = calculatey(heDataList10);
			var Y11:Number = calculatey(heDataList11);
			var Y12:Number = calculatey(heDataList12);
			var Y13:Number = calculatey(heDataList13);
			var Y14:Number = calculatey(heDataList14);
			var Y15:Number = calculatey(heDataList15);
			var Y16:Number = calculatey(heDataList16);
			var Y17:Number = calculatey(heDataList17);
			var Y18:Number = calculatey(heDataList18);
			
			if(Y1==0 || Y2 ==0 || Y3 == 0 || Y4 ==0 || Y5==0 || Y6 ==0 || Y7 == 0 || Y8 ==0 || Y9 == 0 || Y10 == 0
				||Y11==0 || Y12 ==0 || Y13 == 0 || Y14 ==0 || Y15==0 || Y16 ==0 || Y17 == 0 || Y18 ==0){
				analysis4f(Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8,Y9,Y10,Y11,Y12,Y13,Y14,Y15,Y16,Y17,Y18,
					notPassBean1.label, notPassBean2.label, notPassBean3.label ,notPassBean4.label);
			}else{
				var k:int = 6;
				var avey:Number=(Y1+Y2+Y3+Y4+Y5+Y6+Y7+Y8+Y9+Y10+Y11+Y12+Y13+Y14+Y15+Y16+Y17+Y18)/18;
				var aveAT1:Number = (Y1 + Y2 + Y3 + Y16 + Y17 + Y18)/k;
				var aveAT2:Number = (Y4 + Y5 + Y6 + Y10 + Y11 + Y12)/k;
				var aveAT3:Number = (Y7 + Y8 + Y9 + Y13 + Y14 + Y15)/k;
				var aveBT1:Number = (Y1 + Y4 + Y7 + Y10 + Y13 + Y16)/k;
				var aveBT2:Number = (Y2 + Y5 + Y8 + Y11 + Y14 + Y17)/k;
				var aveBT3:Number = (Y3 + Y6 + Y9 + Y12 + Y15 + Y18)/k;
				var aveCT1:Number = (Y1 + Y6 + Y8 + Y10 + Y15 + Y17)/k;
				var aveCT2:Number = (Y2 + Y4 + Y9 + Y11 + Y13 + Y18)/k;
				var aveCT3:Number = (Y3 + Y5 + Y7 + Y12 + Y14 + Y16)/k;
				var aveDT1:Number = (Y1 + Y5 + Y9 + Y12 + Y13 + Y17)/k;
				var aveDT2:Number = (Y2 + Y6 + Y7 + Y10 + Y14 + Y18)/k;
				var aveDT3:Number = (Y3 + Y4 + Y8 + Y11 + Y15 + Y16)/k;
				
				var aveAArry:Array =[];
				aveAArry.push(aveAT1);	
				aveAArry.push(aveAT2);
				aveAArry.push(aveAT3);
				var indexA:int = calculateIndex(aveAArry);
				
				var aveBArry:Array =[];
				aveBArry.push(aveBT1);	
				aveBArry.push(aveBT2);	
				aveBArry.push(aveBT3);
				var indexB:int = calculateIndex(aveBArry);
				
				var aveCArry:Array =[];
				aveCArry.push(aveCT1);	
				aveCArry.push(aveCT2);	
				aveCArry.push(aveCT3);	
				var indexC:int = calculateIndex(aveCArry);
				
				var aveDArry:Array =[];
				aveDArry.push(aveDT1);	
				aveDArry.push(aveDT2);	
				aveDArry.push(aveDT2);
				var indexD:int = calculateIndex(aveDArry);
				
				var SA:Number = ((aveAT1-avey)*(aveAT1-avey)+(aveAT2-avey)*(aveAT2-avey)+(aveAT3-avey)*(aveAT3-avey))*k;
				var SB:Number = ((aveBT1-avey)*(aveBT1-avey)+(aveBT2-avey)*(aveBT2-avey)+(aveBT3-avey)*(aveBT3-avey))*k;
				var SC:Number = ((aveCT1-avey)*(aveCT1-avey)+(aveCT2-avey)*(aveCT2-avey)+(aveCT3-avey)*(aveCT3-avey))*k;
				var SD:Number = ((aveDT1-avey)*(aveDT1-avey)+(aveDT2-avey)*(aveDT2-avey)+(aveDT3-avey)*(aveDT3-avey))*k;
				
				var ST:Number = (Y1-avey)*(Y1-avey)+(Y2-avey)*(Y2-avey)
					+(Y3-avey)*(Y3-avey)+(Y4-avey)*(Y4-avey)
					+(Y5-avey)*(Y5-avey)+(Y6-avey)*(Y6-avey)
					+(Y7-avey)*(Y7-avey)+(Y8-avey)*(Y8-avey)
					+(Y9-avey)*(Y9-avey)+(Y10-avey)*(Y10-avey)
					+(Y11-avey)*(Y11-avey)+(Y12-avey)*(Y12-avey)
					+(Y13-avey)*(Y13-avey)+(Y14-avey)*(Y14-avey)
					+(Y15-avey)*(Y15-avey)+(Y16-avey)*(Y16-avey)
					+(Y17-avey)*(Y17-avey)+(Y18-avey)*(Y18-avey);
				
				var Se:Number = ST-SA-SB-SC-SD;
				
				var fA:Number = (level-1);
				var fB:Number = (level-1);
				var fC:Number = (level-1);
				var fD:Number = (level-1);
				var fT:Number = (level*k-1);//水平数*实验重复次数
				var fe:Number = fT-fA-fB-fC-fD;
				
				var MSA:Number = SA/fA;
				var MSB:Number = SB/fB;
				var MSC:Number = SC/fC;
				var MSD:Number = SD/fD;
				
				var MSe:Number = Se/fe;
				
				var FA:Number = MSA/MSe;
				var FB:Number = MSB/MSe;
				var FC:Number = MSC/MSe;
				var FD:Number = MSD/MSe;
				
				var F:Number = 3.01;//需比较的F值
				
				var hBean:HBean;
				var eBean:EBean = new EBean();
				var tBean:TBean = new TBean();
				
				hBean = new HBean();
				hBean.title = notPassBean1.label;
				hBean.sNum = SA.toFixed(4);
				hBean.fNum = fA.toString();
				hBean.msNum = MSA.toFixed(4);
				hBean.FANum = FA.toFixed(4);
				data1List.addItem(hBean);
				
				hBean = new HBean();
				hBean.title = notPassBean2.label;
				hBean.sNum = SB.toFixed(4);
				hBean.fNum = fB.toString();
				hBean.msNum = MSB.toFixed(4);
				hBean.FANum = FB.toFixed(4);
				data1List.addItem(hBean);
				
				hBean = new HBean();
				hBean.title = notPassBean3.label;
				hBean.sNum = SC.toFixed(4);
				hBean.fNum = fC.toString();
				hBean.msNum = MSC.toFixed(4);
				hBean.FANum = FC.toFixed(4);
				data1List.addItem(hBean);
				
				hBean = new HBean();
				hBean.title = notPassBean4.label;
				hBean.sNum = SD.toFixed(4);
				hBean.fNum = fD.toString();
				hBean.msNum = MSD.toFixed(4);
				hBean.FANum = FD.toFixed(4);
				data1List.addItem(hBean);
				
				eBean.title = "e";
				eBean.sNum = Se.toFixed(4);
				eBean.fNum = fe.toString();
				eBean.msNum = MSe.toFixed(4);
				eBean.FANum = "-";
				
				tBean.title = "T";
				tBean.sNum = ST.toFixed(4);
				tBean.fNum = fT.toString();
				tBean.msNum = "-";
				tBean.FANum = F.toFixed(4);
				data1List.addItem(eBean);
				data1List.addItem(tBean);
				CommonData.getInstance().step3SDgList = data1List;
				
				showresult4E3L(FA,FB,FC,FD,F,indexA,indexB,indexC,indexD);
			}
		}*/
		
		private function calculatey(list:ArrayCollection):Number{
			var temp:Number = 0;
			var sum:Number = 0;
			if(list.length == 0){
				temp = 0;
			}else{
				for each(var item:Number in list){
					if(item){
						sum += item;
					}
				}
				temp = sum / list.length;
			}
			return temp;
		}
		
		private function calculateIndex(aveArray:Array):int{
			var index:int = 0;
			var max:Number = aveArray[0];
			var current:Number = 0;
			for(var i:int = 0; i < aveArray.length ;i++){
				current = aveArray[i];
				if(current >= max){
					max = current;
					index = i;
				}
			}
			return index;
		}
		
		private function calculateMaxIndex(aveArray:Array):Array{
			var max:Number = aveArray[0];
			var tempArray:Array = [];
			for(var i:int = 1; i < aveArray.length ;i++){
				if(aveArray[i] >= max){
					tempArray.push(i);
				}
			}
			return tempArray;
		}
	}
}